package com.car.service.impl;

import com.car.mapper.MaintenanceAppointmentMapper;
import com.car.pojo.MaintenanceAppointment;
import com.car.pojo.MaintenanceAppointmentQueryParam;
import com.car.pojo.PageResult;
import com.car.service.MaintenanceAppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 保养预约Service实现类
 */
@Service
public class MaintenanceAppointmentServiceImpl implements MaintenanceAppointmentService {
    @Autowired
    private MaintenanceAppointmentMapper maintenanceAppointmentMapper;
    
    @Override
    public PageResult<MaintenanceAppointment> page(MaintenanceAppointmentQueryParam param) {
        // 验证页码，确保至少为1
        int pageNum = param.getPage() < 1 ? 1 : param.getPage();
        // 计算起始索引
        param.setPage((pageNum - 1) * param.getPageSize());
        
        // 查询数据
        List<MaintenanceAppointment> list = maintenanceAppointmentMapper.page(param);
        
        // 查询总记录数
        Long total = maintenanceAppointmentMapper.count(param);
        
        // 返回分页结果
        return new PageResult<>(total, list);
    }
    
    @Override
    public MaintenanceAppointment getInfo(Long id) {
        return maintenanceAppointmentMapper.getById(id);
    }
    
    @Override
    public void updateStatus(Long id, String status) {
        maintenanceAppointmentMapper.updateStatus(id, status);
    }
    
    @Override
    public void delete(List<Long> ids) {
        maintenanceAppointmentMapper.deleteBatch(ids);
    }
    
    @Override
    public List<MaintenanceAppointment> list(MaintenanceAppointmentQueryParam param) {
        return maintenanceAppointmentMapper.listAll(param);
    }
}